package flyweight.source;

import java.util.HashMap;

/**
 * 享元工厂 创建并且管理Flyweight对象
 * 确保合理地共享Flyweight
 * 当用户请求一个Flyweight时，提供一个已创建的实例或者创建一个
 * @author cheng:
 * @date 2019/4/25 10:38
 */
public class FlyweightFactory {
    private HashMap<String, Flyweight> flyweights = new HashMap<>(16);

    public FlyweightFactory() {
        flyweights.put("x", new ConcreteFlyweight());
        flyweights.put("y", new ConcreteFlyweight());
        flyweights.put("z", new ConcreteFlyweight());
    }

    public Flyweight getFlyweight(String key){
        return flyweights.get(key);
    }
}
